<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<?php
$company = array(
    '3474' => '華亞科',
    '4938' => '和碩',
    '3481' => '群創',
    '2330' => '台積電',  #台積電
    '2303' => '聯電',
    '2357' => '華碩',
    '2317' => '鴻海',
    '2324' => '仁寶',
    '2382' => '廣達',
    '2308' => '台達電',
    '2325' => '矽品',
    '2454' => '聯發科',
    '2379' => '瑞昱',
    '6285' => '啟碁',
    '3380' => '明泰',
    '3704' => '合勤',
    '2345' => '智邦',
    'BRCM' => 'BRCM',
    'QCOM' => 'QCOM',
    );

function companyData($id)
{
	global $company;
	$todayJobs=0;
	$period=array(
	86400*1,
	86400*3,
	86400*7,
	86400*14,
	86400*30,
	86400*90,
	86400*180);

	$nowSec = time();
	$nowStr=date("Ymd", $nowSec);
	
	echo "<tr>";
	echo "<td>($id)".$company[$id]."</td>";
	echo "<td>";
	if(file_exists("data/$nowStr")) {
		if(file_exists("data/$nowStr/$id")) {
			#readfile("data/$nowStr/$id/jobnum");
			$tmp=file("data/$nowStr/$id/jobnum");
			$todayJobs=rtrim($tmp[0]);
			echo $todayJobs;
		}
	}
	echo "</td>";

	for($i=0;$i<count($period);$i++) {
		echo "<td>";
		$periodStr=date("Ymd", $nowSec-$period[$i]);
		if(file_exists("data/$periodStr")) {
			if(file_exists("data/$periodStr/$id")) {
				echo "<a href=diff.php?id=$id&new=$nowStr&old=$periodStr target=right>";
				#readfile("data/$periodStr/$id/jobnum");
				$star="";
				system("/usr/bin/diff -q data/$nowStr/$id/alljobs data/$periodStr/$id/alljobs > /dev/null", $retval);
				if($retval)
					$star="*";
				$tmp=file("data/$periodStr/$id/jobnum");
				$num=$todayJobs - (int)rtrim($tmp[0]);
				if($num >=0) {
					echo "<font color=green>+$num$star</font>";
				}
				else {
					echo "<font color=red>$num$star</font>";
				}
				echo "</a>";
			}
		}
		echo "</td>";
	}

	echo "</tr>";
}
?>
<table border=1>
<tr>
	<td>公司</td>
	<td>工作數</td>
	<td>昨天</td>
	<td>3日前</td>
	<td>7日前</td>
	<td>14日前</td>
	<td>30日前</td>
	<td>90日前</td>
	<td>180日前</td>
</tr>
<?php
foreach ( $company as $key => $value )
{
	companyData($key);
}
?>
</table>
<h2>符號說明</h2><BR><B>
"+" : 本日的工作數, 相對於之前是增加的<BR>
"-" : 本日的工作數, 相對於之前是減少的<BR>
"*" : 本日的工作職缺，相對於之前是有改變的<BR>
</B>
